package com.accenture.adf.newcodington.module7.sample;

/**
 * 
 * Travel Pass Demo is about checking the number of tickets assigned ticket ID's 
 * 
 * Topic: Demo error handling using assert
 * 
 * Instructions:
 * Create a public class named 'TravelPass_Demo1' with main method() and apply the following changes
 * 1. Declare an integer for number of tickets issued
 * 2. Declare an integer single dimensional array for ticket ID's
 * 3. Initialize the variables number of tickets and the array with number of tickets as the size
 * 4. Print a message to the console as 'Checking Ticket ID's'
 * 5. Use for loop with noOfTickets as the boundary to populate the ticket ID array
 * 		a. Ticket ID can be generated by adding 1 to the loop index
 * 		b. Assign ticket id generated to the respective index in the array
 * 6. Declare an integer variable for the loop index and initialize with zero
 * 7. Loop through the array using a while loop with array size as the boundary
 * 		a. Verify the each value of the ticket id array is not equal to zero using assert statement 
 * 		b. If equal to zero, print a message to the console as 'Mismatch in issuance of ticket id's' as an assertion error
 * 		c. Otherwise, increase the loop index and verify all the values in the array
 * 		d. In case no assertion errors, print "Ticket ID's are assigned to total number of tickets issued." to the console after the loop
 * 
 */


public class TravelPass_Demo {
	
	public static void main(String[] args){		
		
		int noOfTickets;
		int[] ticketID;		
				
		noOfTickets = 5;
		ticketID = new int[noOfTickets];	
		
		System.out.println("Checking Ticket ID's");
		
		//Populate single dimensional array
		int passID = 0;
		for(int i=0;i<noOfTickets;i++){ // modify 'noOfTickets' to 'noOfTickets-1' so the last
			                            // element of the array doesn't get assigned a passID
			                            // which will trigger the assertion exception
			passID = i + 1;
			ticketID[i] = passID;
		}		
		
		//Verify travel pass issued matches noOfTickets
		int index = 0;
		while(index < ticketID.length){
			assert (ticketID[index] != 0) : "Mismatch in issuance of ticket id's";
			System.out.println("Ticket ID = " + ticketID[index]);
			index++;
		}
		
		System.out.println("Ticket ID's are assigned to total number of tickets issued.");
	}	
	
}
